using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using pos.entity;
using idea.tools;
using NHibernate.Criterion;
namespace pos
{
    public partial class ParaClass2Frm : Form
    {
        public ParaClass2Frm()
        {
            InitializeComponent();
        }

        private void ParaClass2Frm_Load(object sender, EventArgs e)
        {
            t_class1 t = new t_class1();
//            DataSet set=t.query("", "order by name");
            
            cboClass1.DropDownStyle = ComboBoxStyle.DropDownList;
            cboClass1.DataSource = t.List(t.DC.AddOrder(Order.Asc("name")));//set.Tables[0];
            cboClass1.DisplayMember = "name";
            cboClass1.ValueMember = "seqID";

            cboClass1.SelectedIndex = 0;


            listView1.Height = this.Height - 100;
            t_class2 t2 = new t_class2();
            ListViewTool lt = new ListViewTool(listView1);
            t2.HeadInsert = lt.insertHead;
            t2.RowInsert = lt.insertRow;
            t2.ExecDataInsertByQuery(null);

        }

        private void cmdAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string str = txtClass2.Text.Trim(); ;
                if (str == "")
                    return;
                long id = Convert.ToInt64(cboClass1.SelectedValue);
                if (id < 0)
                    return;
                t_class2 t = new t_class2();
                sequence s = new sequence(t_class2.SEQN0);
                t.seqID = s.getNumberSequence();
                t.name = str;
                t.parentSeqID = id;
                t.add();
                s.UpdateSequence();
                ListViewTool lt = new ListViewTool(listView1);
                t.RowInsert = lt.insertRow;
                t.ExecDataInsert();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
